﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Rhino.Mocks;

namespace TSVNAddin.Core.Test
{
	[TestFixture]
	public class SetWorkingRootCommandFixture
	{
		[Test]
		public void OnExecuteChooseWorkingRootByDialogAndSetOnWorkingContext()
		{
			var setWorkingRootDialogAdapter = MockRepository.GenerateStub<WorkingRootRecover>((IDialogFactory)null);
			var workingContext = MockRepository.GenerateMock<WorkingContext>(null, null);
			workingContext.Stub(x => x.GetWorkingRoot()).Return(@"c:\svnroot\");
			setWorkingRootDialogAdapter.Stub(x => x.ChooseWorkingRoot(@"c:\svnroot\")).Return(@"c:\myroot\");

			var command = new SetWorkingRootCommand(setWorkingRootDialogAdapter, workingContext);
			command.Execute();

			workingContext.AssertWasCalled(x => x.SetWorkingRoot(@"c:\myroot\"));
		}

		[Test]
		public void OnQueryStatusWhenCanSetWorkingRoot()
		{
			var workingContext = MockRepository.GenerateStub<WorkingContext>(null, null);
			workingContext.Stub(x => x.GetWorkingRoot()).Return(@"c:\svnroot\");
			workingContext.Stub(x => x.CanSetWorkingRoot()).Return(true);

			var command = new SetWorkingRootCommand(null, workingContext);
			var status = command.QueryStatus();

			Assert.AreEqual(CommandStatus.Enabled, status);
		}

		[Test]
		public void OnQueryStatusWhenCanNotSetWorkingRoot()
		{
			var workingContext = MockRepository.GenerateStub<WorkingContext>(null, null);
			workingContext.Stub(x => x.GetWorkingRoot()).Return(@"c:\svnroot\");
			workingContext.Stub(x => x.CanSetWorkingRoot()).Return(false);

			var command = new SetWorkingRootCommand(null, workingContext);
			var status = command.QueryStatus();

			Assert.AreEqual(CommandStatus.Disabled, status);
		}
	}
}
